﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace WpfApplication1
{
	/// <summary>
	/// Interaction logic for Table.xaml
	/// </summary>
	public partial class User : UserControl
	{
        public int ID { get; set; }
		public User()
		{
			this.InitializeComponent();
            wait.Interval = TimeSpan.FromMilliseconds(300);
            wait.Tick += new EventHandler(wait_Tick);
		}
		private void UserControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"MouseMove",true);
		}

		private void UserControl_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"Default",true);
		}

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            VisualStateManager.GoToState(this, "MouseDown", true);
            wait.Start();
        }
        void wait_Tick(object sender, EventArgs e)
        {
            wait.Stop();
            Action temp = () =>{
                if (OnClick != null)
                    OnClick(this);
            };
            this.Dispatcher.Invoke(temp);
        }
        public event Action<object> OnClick;
        DispatcherTimer wait = new DispatcherTimer();

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {

        }
        private void ContexMenu_Click(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            if (ContexMenu != null)
                ContexMenu(this.DataContext, sender);
        }
        public event Action<object, object> ContexMenu;
	}
}